'''
Created on 11 Oct 2009

@author: joao
'''
import unittest

import lib.arithmetics as arithmetics


class DivisorsTest(unittest.TestCase):
	
	def assertSameElements(self, list1, list2):
		self.assertEquals(sorted(list1), sorted(list2))
		
	def assertIn(self, element, list):
		self.assertTrue(element in list)
	
	def testDivisorsOfOne(self):
		divisors = arithmetics.divisors(1)
		self.assertSameElements([1], divisors)
	
	def testDivisorsOfTwo(self):
		divisors = arithmetics.divisors(2)
		self.assertSameElements([1,2], divisors)
	
	def testDivisorsOfFour(self):
		divisors = arithmetics.divisors(4)
		self.assertSameElements([1,2,4], divisors)
		
	def testDivisorsOfFive(self):
		divisors = arithmetics.divisors(5)
		self.assertSameElements([1,5], divisors)
		
	def testDivisorsOfNinety(self):
		divisors = arithmetics.divisors(90)
		self.assertSameElements([1, 2, 3, 5, 6, 9, 10, 15, 18, 30, 45, 90], divisors)
		
	def testDivisorsOfHuge(self):
		divisors = arithmetics.divisors(2783744)
		self.assertEquals(len(divisors), 20)
		self.assertIn(1391872, divisors)
		
	def testFactorialOf5(self):
		factorial  = arithmetics.factorial(5)
		self.assertEquals(factorial, 120)
		
	def testFactorialOf10(self):
		factorial  = arithmetics.factorial(10)
		self.assertEquals(factorial, 3628800)
		
	def testIsPerfect28(self):
		self.assertTrue(arithmetics.isPerfect(8128))	
	
	def testIsPerfect8128(self):
		self.assertTrue(arithmetics.isPerfect(8128))
	
	def testIsPerfect8129(self):
		self.assertFalse(arithmetics.isPerfect(8129))
		
	def testIsDeficient51(self):
		self.assertTrue(arithmetics.isDeficient(51))
		
	def testIsDeficient6(self):
		self.assertFalse(arithmetics.isDeficient(6))
		
	def testIsDeficient100(self):
		self.assertFalse(arithmetics.isDeficient(100))
		
	def testIsAbundant12(self):
		self.assertTrue(arithmetics.isAbundant(12))
		
	def testIsAbundant6(self):
		self.assertFalse(arithmetics.isAbundant(6))
		
	def testIsAbundant100(self):
		self.assertTrue(arithmetics.isAbundant(100))


if __name__ == "__main__":
	#import sys;sys.argv = ['', 'Test.testName']
	unittest.main()